package org.lgiavedoni.android.franq.core.prediction.rule.imp;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

import lombok.Data;

import org.lgiavedoni.android.franq.core.place.Place;
import org.lgiavedoni.android.franq.core.prediction.Prediction;
import org.lgiavedoni.android.franq.core.prediction.imp.PredictedCheckInEvent;
import org.lgiavedoni.android.franq.core.prediction.imp.PredictionEventDate;
import org.lgiavedoni.android.franq.core.prediction.rule.PredictionRule;
import org.lgiavedoni.android.franq.util.date.DateUtil;
@Data
public class PredictionRuleCheckinDay extends PredictionRule {

	private Place place = null;
	private final int day;
	private final int hour;
	private int minute;

	public PredictionRuleCheckinDay(int day, int hour, Place place) {
		super();
		this.day = day;
		this.hour = hour;
		this.place = place;
	}

	public PredictionRuleCheckinDay(int day, int hour, int minute, Place place) {
		super();
		this.day = day;
		this.hour = hour;
		this.place = place;
		this.minute = minute;
	}

	public PredictionRuleCheckinDay(int day, int hour) {
		super();
		this.day = day;
		this.hour = hour;
	}

	@Override
	public List<Prediction> generatePredictions() {
		List<Prediction> l = new ArrayList<Prediction>();

		Calendar predictedDate = Calendar.getInstance();
		predictedDate.set(Calendar.DAY_OF_YEAR, DateUtil.getNextDayOfTheYear(day));
		predictedDate.set(Calendar.HOUR_OF_DAY, hour);
		predictedDate.set(Calendar.MINUTE, minute);
		predictedDate.set(Calendar.SECOND, 0);

		Prediction p = new PredictionEventDate(new PredictedCheckInEvent(place), predictedDate.getTime());
		l.add(p);

		return l;
	}

	public Date getDate() {
		Calendar c = Calendar.getInstance();
		c.set(Calendar.HOUR_OF_DAY, hour);
		c.set(Calendar.MINUTE, minute);
		c.set(Calendar.SECOND, 0);
		c.set(Calendar.DAY_OF_WEEK_IN_MONTH, day);
		return c.getTime();
	}

	public String getDaysOfFormated() {
		return DateUtil.parseDayOfWeekToString(this.day);
	}

	public String getTimeFormated() {
		return String.valueOf(hour + ":" + minute);
	}
	
	@Override
	public String toString() {
		return "[" + this.place.getName() + "] - " + DateUtil.parseDayOfWeekToString(this.day);
	}
}
